package cn.wangsy.zhidao.p20170110;

public class ReplaceTest {

	public static void main(String[] args) {
		String m="hello ?,nice+(book) ?-? good";
		String[] n={"","he","she"};
		System.out.println(relapce(m, n));
		System.out.println(getM(m, n));
		
		int PAGESIZE = 10;
		int CurrentPage = 3;
		String sql = "SELECT * FROM authcode where A_Id in (SELECT * FROM authcode where A_Id in (SELECT * FROM authcode where A_Id not in (Select * from authcode order by A_Id desc limit " + PAGESIZE * CurrentPage + ")order by A_Id desc limit " + PAGESIZE + ")order by A_Id desc)order by A_Id desc";
		System.out.println(sql);
		
	}

	public static String relapce(String old,String[]params){
		int count = 0;
		while(old.indexOf("?")!=-1 && count < params.length){
			old = old.substring(0, old.indexOf("?")) + params[count] + old.substring(old.indexOf("?")+1);
			count++;
		}
		return old;
	}
	
	//你要的方法
    static String getM(String m,String[] n){
        String tmp=m;
        for(String re:n){
            tmp=tmp.replaceFirst("[?]", re);
        }
        return tmp;
    }
     
//    public static void main(String[] args) {
//        String m="hello ?,nice+(book) ?-? good";
//        //char类型只能放一个字符；遂换成String类型
//        String[] n={"","he","she"};
//        String new_m=getM(m,n);
//        System.out.println(new_m);
//    }
	
}
